export function configRouter(router) {
    // 异步加载组件
    function async(component) {
        return resolve => require(['./components/' + component + '.vue'], resolve);
    }

    router.map({
        '/guide': {
            component: async('guide'),
            // header里面的参数：
            // @disable: 选择是否不现实header
            // @slot: 显示在正中间的html
            // @left_slot: 显示左边的html
            // @right_slot: 显示在右边的html
            // @show_back: 是否显示返回箭头
            // @back_text: 设置返回文字
            // @prevent_go_back: 是否阻止点击Back时的后退，默认为false
            // @show_more: 是否显示更多图标
            // @on_click_back: 需要设置为一个函数，点击后退图片或文字的时候调用的函数，只有当prevent_go_back为true才生效
            // @on_click_more: 需要设置为一个函数，点击更多图片或文字的时候调用的函数
            header: {disable: true},
            subRoutes: {
                '/': {
                    component: async('article/m-article'),
                },
                '/category/:categ_id': {
                    component: async('article/m-category'),
                }
            },
        },
        '/article': {
            name: 'article',
            component: async('article/m-article-docker'),
            header: {slot: '攻略详情', show_back: true},
            subRoutes: {
                '/': {
                    component: async('article/m-article'),
                },
                ':article': {
                    component: async('article/m-article'),
                }
            }
        },
        '/hot': {
            component: async('products'),
            header: {slot: '热门'},
        },
        '/hot/category': {
            component: async('products'),
            header: {slot: '分类'},
        },
        '/category': {
            component: async('category'),
            header: {slot: '分类'},
        },
        '/category/products': {
            component: async('products'),
            header: { slot: '产品列表', show_back: true},
        },
        '/my': {
            component: async('my'),
            header: {disable: true},
        },
        '/my/config': {
            component: async('config/config'),
            header: {slot: '设置', show_back: true},
        },
        '/my/config/address': {
            component: async('config/address'),
            header: {slot: '地址管理', show_back: true},
        },
        '/my/config/address/edit': {
            component: async('config/address-edit'),
            header: {slot: '编辑收货地址', show_back: true}
        },
        '/my/orders': {
            component: async('order/orders'),
            header: { show_back: true, slot: '订单' },
        },
        '/my/orders/order': {
            component: async('order/order'),
            header: { slot: '订单', show_back: true},
        },
        '/product/:product': {
            name: 'product',
            component: async('product'),
            header: {disable: true},
        },
        '/product/:product/order/edit': {
            component: async('order/order-edit'),
            header: { slot: '订单编辑', show_back: true},
        },
        '/cart': {
            name: 'cart',
            component: async('shopping_cart'),
            header: { slot: '购物车'},
        },
        '/cart/order': {
            component: async('order/order'),
            header: { slot: '订单', show_back: true},
        },
        '/cart/order/edit': {
            component: async('order/order-edit'),
            header: { slot: '订单编辑', show_back: true},
        },
        '/cart/order/edit/address': {
            component: async('order/address'),
            header: { slot: '地址选择', show_back: true},
        }
    });

    router.afterEach(({to: {router, header}}) => {
        if (header && router.app.display_header) {
            header.on_click_more = header.on_click_more || new Function();
            header.on_click_back = header.on_click_back || new Function();

            router.app.display_header(header);
        }
    });
}
